home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12036 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  73 lines

  1. Path: news.sover.net!news
  2. From: sstryker@sover.net (Stew Stryker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Does VAX C++ support templates?
  5. Date: Sun, 17 Mar 1996 17:59:10 -0400
  6. Organization: Southern Vermont Network
  7. Message-ID: <19960317215910.sstryker@sover.net>
  8. References: <19960317181747.sstryker@sover.net>
  9. NNTP-Posting-Host: pm0a15.wrj.sover.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NewsReader: Emissary News v1.01.007, by Wollongong Inc.
  14.  
  15. It seems that VAX C++ doesn't support templates, at least not in the form
  16. from the (non-VAX) examples I'm working from.
  17.  
  18. I tried the following:
  19.  
  20.  
  21. #include <iostream.h>
  22. const int DefaultSize = 10;
  23.  
  24. template <class T>
  25. class Array
  26. {
  27.     public:
  28.         // constructors
  29.         Array(int itsSize = DefaultSize);
  30.         Array(const Array &rhs);
  31.         ~Array() { delete [] pType; }
  32.  
  33.         // Operators
  34.         Array& operator=(const Array&);
  35.         T& operator[](int offSet) { return pType[offSet]; }
  36.  
  37.         // Accessors
  38.         int getSize() { return itsSize; }
  39.  
  40.     private:
  41.         T *pType;
  42.         int itsSize;
  43. };
  44.  
  45. main()
  46. {
  47.     Array<int> theNumbers;
  48.  
  49.     for (int i = 0; i < theNumbers.getSize(); i++)
  50.         theNumbers[i] = i * 2;
  51.  
  52.     for (i = 0; i < theNumbers.getSize(); i++)
  53.         cout << "[" << i << "]: " << theNumbers[i] << ".\n";
  54.  
  55.     cout << "Done." << endl;
  56. }
  57.  
  58.  
  59. And the compiler complained about the constructor:
  60.  
  61.     Array(const Array &rhs);
  62.  
  63. saying that Array's type (the second instance) wasn't specified.  I did the
  64. same at the other places in the definition where Array was specified.  I
  65. tried inserting <T> in those place, which compiled.  But then the linker
  66. said that the symbol Array was undefined.
  67.  
  68. Suggestions?
  69.  
  70. Thanks,
  71.  
  72. Stew
  73.